package com.yanqu.road.entity.unioncampwar.cross;


import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 商帮阵营数据,周二0点报名期开始时分好组
 */
@FieldTypeAnnotation(tableName = "t_c_union_camp_war_group", autoSave = true)
public class CrossUnionCampWarGroupData extends DataObject {

    @FieldTypeAnnotation(desc = "对应的中心服配置分组id", update = true, select = true)
    private int centerGroupId;
    @FieldTypeAnnotation(desc = "分组Id", update = true, select = true)
    private int groupId;
    @FieldTypeAnnotation(desc = "周", update = true, select = true)
    private int weekId;
    @FieldTypeAnnotation(desc = "服务器列表")
    private Set<Long> serverSet = new ConcurrentHashSet<>();

    private ConcurrentHashMap<String, CrossUnionCampWarGroupUnionData> unionMap = new ConcurrentHashMap<>();

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        if (this.groupId != groupId) {
            this.groupId = groupId;
            setOp(DataStatus.Update);
        }
    }

    public int getCenterGroupId() {
        return centerGroupId;
    }

    public void setCenterGroupId(int centerGroupId) {
        this.centerGroupId = centerGroupId;
    }

    public Set<Long> getServerSet() {
        return serverSet;
    }

    public void setServerSet(Set<Long> serverSet) {
        this.serverSet = serverSet;
    }

    public ConcurrentHashMap<String, CrossUnionCampWarGroupUnionData> getUnionMap() {
        return unionMap;
    }

    public void setUnionMap(ConcurrentHashMap<String, CrossUnionCampWarGroupUnionData> unionMap) {
        this.unionMap = unionMap;
    }

    public void putUnionData(CrossUnionCampWarGroupUnionData unionData) {
        this.unionMap.put(unionData.getUnionId(), unionData);
    }

    public List<CrossUnionCampWarGroupUnionData> getUnionDataList() {
        List<CrossUnionCampWarGroupUnionData> list = new ArrayList<>(this.unionMap.values());
        return list;
    }

    public Map<Integer,List<CrossUnionCampWarGroupUnionData>> getCampUnionListMap(){
        Map<Integer,List<CrossUnionCampWarGroupUnionData>> map = new ConcurrentHashMap<>();
        for (CrossUnionCampWarGroupUnionData groupUnionData : unionMap.values()) {
            List<CrossUnionCampWarGroupUnionData> list = map.get(groupUnionData.getCampId());
            if (list == null) {
                list = new ArrayList<>();
                map.put(groupUnionData.getCampId(), list);
            }
            list.add(groupUnionData);
        }

        return map;
    }

    public CrossUnionCampWarGroupUnionData getGroupUnionData(String unionId) {
        return this.unionMap.get(unionId);
    }

    public int getWeekId() {
        return weekId;
    }

    public void setWeekId(int weekId) {
        this.weekId = weekId;
    }
}
